package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.TravelCommend;
import cn.wolfcode.luowowo.article.mapper.TravelCommendMapper;
import cn.wolfcode.luowowo.article.mapper.TravelContentMapper;
import cn.wolfcode.luowowo.article.mapper.TravelMapper;
import cn.wolfcode.luowowo.article.query.TravelCommendQuery;
import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by admin on 2019/8/12.
 */
@Service
public class
TravelCommendServiceImpl implements ITravelCommendService {

    @Autowired
    private TravelCommendMapper commendMapper;

    @Override
    public PageInfo<TravelCommend> query(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo<>(commendMapper.seleceForList(qo));
    }

    @Override
    public void saveOrUpdate(TravelCommend travelCommend) {


        if (travelCommend.getSequence() == null) {
            int max = commendMapper.selectMaxSequence(travelCommend.getTravelId());
            travelCommend.setSequence(max + 1);
        }
        
        if (travelCommend.getId() == null) {
            commendMapper.insert(travelCommend);
        } else {
            commendMapper.updateByPrimaryKey(travelCommend);
        }
    }

    @Override
    public List<TravelCommend> selectCommendTop5() {
        return commendMapper.selectCommendTop5();
    }
}
